package com.wsmhz.web.fitter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import java.io.IOException;
import java.util.Date;

/**
 * create by tangbj on 2018/3/25
 * 每个API都会处理的时间过滤器
 */
//@Component   还是在webConfig中配置吧
public class ApiTimeFilter implements Filter {

    private static Logger logger = LoggerFactory.getLogger(ApiTimeFilter.class);

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        logger.info("ApiTimeFilter init");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        logger.info("ApiTimeFilter start");
        long start = new Date().getTime();
        filterChain.doFilter(servletRequest, servletResponse);
        logger.info("ApiTimeFilter 耗时:"+ (new Date().getTime() - start));
        logger.info("ApiTimeFilter finish");
    }

    @Override
    public void destroy() {
        logger.info("ApiTimeFilter destroy");
    }


}
